<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>登录页面</title>
</head>

<script src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css">
<body>
<h1 style="color: red">${requestScope.error}</h1>
<div style="width:100%;">
<form action="${pageContext.request.contextPath}/login" method="post">
    <div class="input-group">
        <label class="input-group-addon">名字：</label>
        <input type="text" name="name" class="form-control" style="width: 20%"><br/>
    </div>
    <br>
    <div class="input-group">
        <label class="input-group-addon">密码：</label>
        <input type="password" name="password" class="form-control" style="width: 20%"><br/>
    </div>
    <br/>
    <div class="input-group">
        <input type="text" name="code" class="form-control" placeholder="请输入验证码" style="width: 50%;height: 40px">
        <img src="${pageContext.request.contextPath}/captcha" class="form-control" id="cap" style="border: 0px;width: 50%;height: 40px">
    </div>
<br/>
    <input type="submit" value="登录" class="btn btn-primary">
</form>
</div>
<hr/>

<button type="button" class="btn btn-primary" onclick="sendAjax()">发送json请求</button>

<script>


    $(function (){
        var cap= $("#cap").attr("src");
        $("#cap").click(function (){
            $(this).attr("src",cap + "?v=" + new Date());
        });
    });
    function sendAjax(){
        var user = {name:"wkk",password:"1223"};
        $.ajax({
            url: "http://localhost:8080${pageContext.request.contextPath}/json/test6",
            type: "post",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(user),
            success : function (res) {
                console.log(res);
            }
        });
    }
</script>
</body>
</html>